package dp.gr03.payroll.application.commands;

import java.util.GregorianCalendar;

import dp.gr03.payroll.affiliationTransactions.ServiceChargeTransaction;
import dp.gr03.payroll.application.DateParser;
import dp.gr03.payroll.exception.InvalidArgumentsException;
import dp.gr03.payroll.exception.PayRollException;
import dp.gr03.payroll.payrollApplication.Transaction;

public class ServiceChargeCommand implements TransactionParser
{

    @Override
    public String getActionString()
    {
        return "ServiceCharge";
    }

    @Override
    public Transaction parse(String[] arguments) throws PayRollException
    {
        if (arguments.length == 3)
        {
            int memberId = 0;
            GregorianCalendar date = null;
            double amount = 0;
            try{
                memberId = Integer.parseInt(arguments[1]);
                date = DateParser.parseDate(arguments[2]);
                amount = Double.parseDouble(arguments[3]);
            }
            catch(NumberFormatException e){
                throw new PayRollException("Member ID and amount should be numbers.");
            }
            return new ServiceChargeTransaction(memberId, date, amount);
        } else
        {
            throw new InvalidArgumentsException();
        }
    }
}
